using System;
using System.Collections.Generic;
using System.Text;

namespace HexterConsulting
{
    class Program
    {
        private static bool errorOccured = false;
        static void Main(string[] args)
        {
            
            if (args[0] != null && args[0] != string.Empty && System.IO.File.Exists(args[0]))
            {
                BinaryToCSVConverter binaryconverter;
                binaryconverter = new BinaryToCSVConverter(args[0]);

                Console.WriteLine("Proccesing Logfile");
                binaryconverter.Convert();

                PerformanceLog p = new PerformanceLog(binaryconverter.DestinationFilename);
                string datadir = @"data\";
                string chartdir = @"charts\";

                Processor pr = new Processor(p, datadir, chartdir);
                pr.Progress += new EventHandler<Processor.ProgressEventArgs>(pr_Progress);
                pr.Error += new EventHandler<Processor.ExceptionEventArgs>(pr_Error);

                Console.WriteLine("Summerizing Data");
                pr.MakeSummaryData();
                Console.WriteLine("Creating Charts");
                pr.MakeCharts();
                Console.WriteLine("Complete");

                if (errorOccured)
                    Console.Read();
            }
            else
                Console.WriteLine("First argument must be the full path to a binary circular performance log file.");
        }

        static void pr_Error(object sender, Processor.ExceptionEventArgs e)
        {
            errorOccured = true;
            Console.WriteLine(e.ToString());
        }

        static void pr_Progress(object sender, Processor.ProgressEventArgs e)
        {
            Console.WriteLine(e.ToString());
        }
        
    }
}
